package com.church.daoimpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.church.dao.TasklistDao;
import com.church.db.Tasklist;

public class TasklistDaoImpl extends HibernateDaoSupport implements TasklistDao {
	@Override
	public List<Tasklist> getTasklistByGroup(String group) {
		List<Tasklist> list = this.getHibernateTemplate().find("from Tasklist as tl where tl.group='"+group+"' and tl.state!='3'");
		return list;
	}

	@Override
	public String addTask(Tasklist task) {
		this.getHibernateTemplate().save(task);
		return "success";
	}

	@Override
	public String removeTask(long id) {
		Tasklist task=getTaskById(id);
		if(task!=null)
		{
			this.getHibernateTemplate().delete(task);
			return "success";
		}
		return "error";
	}

	@Override
	public String updateTask(Tasklist task) {
		this.getHibernateTemplate().persist(task);
		return "success";
	}

	@Override
	public Tasklist getTaskById(long id) {
		List<Tasklist> list = this.getHibernateTemplate().find("from Tasklist as qa where tl.id="+id+" and state!='3'");
		if(list.size()>0)
		{
			return list.get(0);
		}
		return null;
	}

}
